package com.hlxt.nj.busi.dao.impl;

import com.hlxt.nj.base.dao.BaseDao;
import com.hlxt.nj.busi.dao.TUserCouDAO;
import com.hlxt.nj.busi.model.TUserCou;
import com.hlxt.nj.busi.model.TUserCouCriteria;
import com.hlxt.nj.common.PageBean;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.stereotype.Repository;

@Repository
public class TUserCouDAOImpl extends BaseDao implements TUserCouDAO {

    public TUserCouDAOImpl() {
        super();
    }

    public int countByExample(TUserCouCriteria example) {
        Integer count = (Integer)  getSqlMapClientTemplate().queryForObject("T_USER_COU.countByExample", example);
        return count;
    }

    public int deleteByExample(TUserCouCriteria example) {
        int rows = getSqlMapClientTemplate().delete("T_USER_COU.deleteByExample", example);
        return rows;
    }

    public int deleteByPrimaryKey(Integer id) {
        TUserCou _key = new TUserCou();
        _key.setId(id);
        int rows = getSqlMapClientTemplate().delete("T_USER_COU.deleteByPrimaryKey", _key);
        return rows;
    }

    public void insert(TUserCou record) {
        getSqlMapClientTemplate().insert("T_USER_COU.insert", record);
    }

    public void insertSelective(TUserCou record) {
        getSqlMapClientTemplate().insert("T_USER_COU.insertSelective", record);
    }

    @SuppressWarnings("unchecked")
    public List<TUserCou> selectByExample(TUserCouCriteria example) {
        List<TUserCou> list = getSqlMapClientTemplate().queryForList("T_USER_COU.selectByExample", example);
        return list;
    }

    public TUserCou selectByPrimaryKey(Integer id) {
        TUserCou _key = new TUserCou();
        _key.setId(id);
        TUserCou record = (TUserCou) getSqlMapClientTemplate().queryForObject("T_USER_COU.selectByPrimaryKey", _key);
        return record;
    }

    public int updateByExampleSelective(TUserCou record, TUserCouCriteria example) {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = getSqlMapClientTemplate().update("T_USER_COU.updateByExampleSelective", parms);
        return rows;
    }

    public int updateByExample(TUserCou record, TUserCouCriteria example) {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = getSqlMapClientTemplate().update("T_USER_COU.updateByExample", parms);
        return rows;
    }

    public int updateByPrimaryKeySelective(TUserCou record) {
        int rows = getSqlMapClientTemplate().update("T_USER_COU.updateByPrimaryKeySelective", record);
        return rows;
    }

    public int updateByPrimaryKey(TUserCou record) {
        int rows = getSqlMapClientTemplate().update("T_USER_COU.updateByPrimaryKey", record);
        return rows;
    }

    @SuppressWarnings("unchecked")
    public void selectPageBeanByExample(TUserCouCriteria example, PageBean pageBean) {
        example.setFirstResult(pageBean.getRsFirstNumber() - 1);
        example.setMaxResults(pageBean.getLength());
        Integer count = (Integer)  getSqlMapClientTemplate().queryForObject("T_USER_COU.countByExample", example);
        List<TUserCou> list = getSqlMapClientTemplate().queryForList("T_USER_COU.selectByExample", example);
        pageBean.setTotalRecords(count);
        pageBean.setResults(list);
    }

    @SuppressWarnings("unchecked")
    public void selectPageBean(TUserCou record, PageBean pageBean) {
        Map<String,Object> condition = new HashMap<String,Object>();
        try {
            condition = PropertyUtils.describe(record);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        condition.put("firstResult", pageBean.getRsFirstNumber() - 1);
        condition.put("endResult", pageBean.getLength() + pageBean.getRsFirstNumber() - 1);
        condition.put("maxResults", pageBean.getLength());
        Integer count = (Integer)  getSqlMapClientTemplate().queryForObject("T_USER_COU.countByPo", record);
        List<TUserCou> list = getSqlMapClientTemplate().queryForList("T_USER_COU.selectPageBeanByMap", condition);
        pageBean.setTotalRecords(count);
        pageBean.setResults(list);
    }

    public int count(TUserCou record) {
        Integer count = (Integer)  getSqlMapClientTemplate().queryForObject("T_USER_COU.countByPo", record);
        return count;
    }

    @SuppressWarnings("unchecked")
    public List<TUserCou> select(TUserCou record) {
        Map<String,Object> condition = new HashMap<String,Object>();
        try {
            condition = PropertyUtils.describe(record);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        condition.put("firstResult", null);
        condition.put("endResult", null);
        condition.put("maxResults", null);
        List<TUserCou> list = getSqlMapClientTemplate().queryForList("T_USER_COU.selectPageBeanByMap", condition);
        return list;
    }

    protected static class UpdateByExampleParms extends TUserCouCriteria {
        private Object record;

        public UpdateByExampleParms(Object record, TUserCouCriteria example) {
            super(example);
            this.record = record;
        }

        public Object getRecord() {
            return record;
        }
    }
}